package kr.ac.chungbuk;

import java.util.List;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	IBoardDAO ibaties = new IBoardDAO();
	ArrayList<BoardDTO> boardList = new ArrayList<BoardDTO>();
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		logger.info("Welcome home! The client locale is {}.", locale);
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		
		String formattedDate = dateFormat.format(date);
		
		model.addAttribute("serverTime", formattedDate );
		
		return "home";
	}

	@RequestMapping("index")
	public ModelAndView index(HttpSession session){
		List list=ibaties.selectAll();
		List list2=ibaties.selectAllItem();
		ModelAndView modelAndView = new ModelAndView();
		UserDTO user=(UserDTO)session.getAttribute("user");
		if(user!=null){
			modelAndView.addObject("user",user);
		}
		modelAndView.addObject("boardList",list);
		modelAndView.addObject("itemList", list2);
		modelAndView.setViewName("../views/mainHome/index");
		return modelAndView;
	}
	@RequestMapping("impor")
	public String impor(){
		return "../views/impormation/impor";
	}
	@RequestMapping("imporPic")
	public String imporPic(){
		return "../views/impormation/imporPic";
	}
	@RequestMapping("imporPeo")
	public String imporPeo(){
		return "../views/impormation/imporPeo";
	}
	
	@RequestMapping("earring")
	public String earring(){
		return "../views/items/earring";
	}
	@RequestMapping("bracelet")
	public String bracelet(){
		return "../views/items/bracelet";
	}
	@RequestMapping("necklace")
	public String necklace(){
		return "../views/items/necklace";
	}
	@RequestMapping("set")
	public String set(){
		return "../views/items/set";
	}
	@RequestMapping("come")
	public String come(){
		return "../views/howUse/come";
	}
	@RequestMapping("kakao")
	public String kakao(){
		return "../views/howUse/kakao";
	}
	@RequestMapping("internet")
	public String internet(){
		return "../views/howUse/internet";
	}
	/*@RequestMapping("reservation")
	public String reservation(){
		return "../views/question/reservation";
	}*/
	@RequestMapping("question")
	public String question(){
		return "../views/question/question";
	}
	@RequestMapping("goldmoney")
	public String goldmoney(){
		return "../views/board/goldmoney";
	}
	@RequestMapping("otherimpor")
	public String otherimpor(){
		return "../views/board/otherimpor";
	}
	@RequestMapping("notice")
	public String notice(){
		return "../views/board/notice";
	}
	@RequestMapping("event")
	public String event(){
		return "../views/board/event";
	}
	@RequestMapping("joinHome")
	public String joinHome(){
		return "../views/joinHome/joinHome";
	}
	@RequestMapping("userEntrySuccess")
	public String userEntry(){
		return "../view/joinHome/userEntrySuccess";
	}
	
	
}
